using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace qPrintComponent
{
    //typedef struct _DRIVER_INFO_8W {
    //    DWORD      cVersion;
    //    LPWSTR     pName;                    // QMS 810
    //    LPWSTR     pEnvironment;             // Win32 x86
    //    LPWSTR     pDriverPath;              // c:\drivers\pscript.dll
    //    LPWSTR     pDataFile;                // c:\drivers\QMS810.PPD
    //    LPWSTR     pConfigFile;              // c:\drivers\PSCRPTUI.DLL
    //    LPWSTR     pHelpFile;                // c:\drivers\PSCRPTUI.HLP
    //    LPWSTR     pDependentFiles;          // PSCRIPT.DLL\0QMS810.PPD\0PSCRIPTUI.DLL\0PSCRIPTUI.HLP\0PSTEST.TXT\0\0
    //    LPWSTR     pMonitorName;             // "PJL monitor"
    //    LPWSTR     pDefaultDataType;         // "EMF"
    //    LPWSTR     pszzPreviousNames;        // "OldName1\0OldName2\0\0
    //    FILETIME   ftDriverDate;
    //    DWORDLONG  dwlDriverVersion;
    //    LPWSTR     pszMfgName;
    //    LPWSTR     pszOEMUrl;
    //    LPWSTR     pszHardwareID;
    //    LPWSTR     pszProvider;
    //    LPWSTR     pszPrintProcessor;
    //    LPWSTR     pszVendorSetup;
    //    LPWSTR     pszzColorProfiles;
    //    LPWSTR     pszInfPath;
    //    DWORD      dwPrinterDriverAttributes;
    //    LPWSTR     pszzCoreDriverDependencies;
    //    FILETIME   ftMinInboxDriverVerDate;
    //    DWORDLONG  dwlMinInboxDriverVerVersion;
    //}

    public sealed class DriverInfo8 : qSafeDriverInfo
    {
        public DriverInfo8(SafeHandle PrinterHandle)
            : base(PrinterHandle, 8)
        { }
        
        public DriverInfo8(IntPtr MemoryHandle)
            : base(MemoryHandle, 8)
        { }

        public override string ToString()
        {
            return Provider;
        }

        [Description(@"Specifies the operating system version for which the driver was written. Currently it can be the following. Value Meaning 3 Driver for Windows 2000/XP.")]
        public int Version
        {
            get { return GetIntField(0); }
        }
        [Description(@"The name of the driver (for example, QMS 810).")]
        public string Name
        {
            get { return GetStringField(1); }
        }
        [Description(@"The environment for which the driver was written (for example, Windows NT x86, Windows IA64, Windows x64, Windows NT R4000, Windows NT Alpha_AXP, Windows 4.0, or Windows NT PowerPC).")]
        public string Environment
        {
            get { return GetStringField(2); }
        }
        [Description(@"The file that contains the device driver (for example, C:\DRIVERS\Pscript.dll).")]
        public string DriverPath
        {
            get { return GetStringField(3); }
        }
        [Description(@"The file that contains driver data (for example, C:\DRIVERS\Qms810.ppd).")]
        public string DataFile
        {
            get { return GetStringField(4); }
        }
        [Description(@"Tthe device driver's configuration dynamic-link library (for example, C:\DRIVERS\Pscrptui.dll).")]
        public string ConfigFile
        {
            get { return GetStringField(5); }
        }
        [Description(@"The device driver's help file (for example, C:\DRIVERS\Pscrptui.hlp).")]
        public string HelpFile
        {
            get { return GetStringField(6); }
        }
        [Description(@"The files the driver depends on. Each file name is separated by a backslash and a null character (for example, Pscript.dll\0QMS810.ppd\0Pscriptui.dll\0Pscriptui.hlp\0Pstest.txt\0\0).")]
        public string DependentFiles
        {
            get { return GetStringField(7); }
        }
        [Description(@"A language monitor (for example, 'PJL monitor'). This member can be NULL and should be specified only for printers capable of bidirectional communication.")]
        public string MonitorName
        {
            get { return GetStringField(8); }
        }
        [Description(@"The default data type of the print job (for example, 'EMF').")]
        public string DefaultDataType
        {
            get { return GetStringField(9); }
        }
        [Description(@"Any previous printer driver names that are compatible with this driver (for example, OldName1\0OldName2\0\0).")]
        public string PreviousNames
        {
            get { return GetStringField(10); }
        }
        [Description(@"The date of the driver package, as coded in the driver files.")]
        public string FileTime
        {
            get
            {
                long l = GetLongField(11);
                if (l == 0) return "Unknown";
                return DateTime.FromFileTimeUtc(l).ToShortDateString();
            }
        }
        [Description(@"Version number of the driver. This comes out of the version structure of the driver.")]
        public Int64 Fileversion
        {
            get { return GetLongField(14); }
        }
        [Description(@"The manufacturer's name.")]
        public string ManufacterName
        {
            get { return GetStringField(16); }
        }
        [Description(@"The URL for the manufacturer.")]
        public string ManufacterUrl
        {
            get { return GetStringField(17); }
        }
        [Description(@"The hardware ID for the printer driver.")]
        public string ManufacterHardWareId
        {
            get { return GetStringField(18); }
        }
        [Description(@"The provider of the printer driver (for example, 'Microsoft Windows 2000').")]
        public string Provider
        {
            get { return GetStringField(19); }
        }
        [Description(@"The PrintProcessor of the printer driver (for example, '').")]
        public string PrintProcessor
        {
            get { return GetStringField(20); }
        }
        [Description(@"The VendorSetup of the printer driver (for example, '').")]
        public string VendorSetup
        {
            get { return GetStringField(21); }
        }
        [Description(@"The ColorProfiles of the printer driver (for example, '').")]
        public string ColorProfiles
        {
            get { return GetStringField(22); }
        }
        [Description(@"The InfPath of the printer driver (for example, '').")]
        public string InfPath
        {
            get { return GetStringField(23); }
        }
        [Description(@"")]
        public int PrinterDriverAttributes
        {
            get { return GetIntField(24); }
        }
        [Description(@"The CoreDriverDependencies of the printer driver (for example, '').")]
        public string ZCoreDriverDependencies
        {
            get { return GetStringField(25); }
        }
        [Description(@"")]
        public string MinInboxDriverVerDate
        {
            get
            {
                long l = GetLongField(26);
                if (l == 0) return "Unknown";
                return DateTime.FromFileTimeUtc(l).ToShortDateString();
            }
        }
        [Description(@"")]
        public string MinInboxDriverVerVersion
        {
            get
            {
                long l = GetLongField(29);
                if (l == 0) return "Unknown";
                return DateTime.FromFileTimeUtc(l).ToShortDateString();
            }
        }


    }
}
